package network

import (
	"gitlab.local/golibrary/sysconfig"
	"net"
	"sync"
)

// Networkset : 未实现
type Networkset interface {
	GetInterfaces() (result map[string]*NetInfo)
	GetIntranetIpv4() string
	DefaultRJ45() (result string)
}

type LanIpGetter interface {
	GetLanIp() (string, error)
}

type NetInfo struct {
	Name       string `json:"name"`        //保存网卡名
	DHCP       bool   `json:"dhcp"`        //是否自动获取IP
	IPv4       net.IP `json:"ipv4"`        //保存ipv4
	NetMask    string `json:"netmask"`     //保存netmask
	NetBits    int    `json:"netbits"`     //保存子网的位
	HardAddr   string `json:"mac"`         //保存mac
	Getway     net.IP `json:"gateway"`     //默认网关
	MTU        int    `json:"mtu"`         //mtu
	IPv6       net.IP `json:"ipv6"`        //ipv6
	State      bool   `json:"-"`           //是否接入网络running
	PublicIpv6 net.IP `json:"public_ipv6"` //公网ipv6
}

type linuxRouteStruct struct {
	Iface       string
	Destination string
	Gateway     string
	Flags       string
	RefCnt      string
	Use         string
	Metric      string
	Mask        string
	MTU         string
	Window      string
	IRTT        string
}

type NetDevivce struct {
	route         string
	config        string
	netlist       map[string]*NetInfo
	listLock      sync.Mutex
	configService sysconfig.Getter
}

func New(configService sysconfig.Getter) *NetDevivce {
	lan := &NetDevivce{
		route:         "/proc/net/route",
		config:        "/etc/tos/config/network.json",
		configService: configService,
	}
	return lan
}
